package com.huawei.hwid.core.d.c;

import com.huawei.hwid.core.d.b.e;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public final class d implements a {
    private static d a;

    private d() {
    }

    public static synchronized d b() {
        d dVar;
        synchronized (d.class) {
            if (a == null) {
                a = new d();
            }
            dVar = a;
        }
        return dVar;
    }

    private static int c() {
        try {
            Class cls = Class.forName("android.telephony.TelephonyManager");
            Method declaredMethod = cls.getDeclaredMethod("getDefaultSim", (Class[]) null);
            Object invoke = cls.getDeclaredMethod("getDefault", (Class[]) null).invoke(null, (Object[]) null);
            declaredMethod.setAccessible(true);
            return ((Integer) declaredMethod.invoke(invoke, (Object[]) null)).intValue();
        } catch (RuntimeException e) {
            e.a("mutiCardMTKImpl", "RuntimeException", true);
            return -1;
        } catch (Exception e2) {
            e.a("mutiCardMTKImpl", "Exception", true);
            return -1;
        } catch (Error e3) {
            e.a("mutiCardMTKImpl", "Error", true);
            return -1;
        }
    }

    private static Object d() {
        Object obj = null;
        try {
            Class cls = Class.forName("com.mediatek.telephony.TelephonyManagerEx");
            obj = cls.getDeclaredMethod("getDefault", new Class[0]).invoke(cls, new Object[0]);
        } catch (RuntimeException e) {
            e.a("mutiCardMTKImpl", " getDefaultTelephonyManagerEx wrong RuntimeException", true);
        } catch (Exception e2) {
            e.a("mutiCardMTKImpl", " getDefaultTelephonyManagerEx wrong ", true);
        }
        return obj;
    }

    public int a() {
        return c();
    }

    public int a(int i) {
        Class[] clsArr = new Class[]{Integer.TYPE};
        Object[] objArr = new Object[]{Integer.valueOf(i)};
        try {
            int intValue;
            Object d = d();
            if (d != null) {
                intValue = ((Integer) d.getClass().getDeclaredMethod("getSimState", clsArr).invoke(d, objArr)).intValue();
            } else {
                intValue = 0;
            }
            return intValue;
        } catch (NoSuchMethodException e) {
            e.d("mutiCardMTKImpl", "NoSuchMethodException getSimState wrong ", true);
            return 0;
        } catch (IllegalArgumentException e2) {
            e.d("mutiCardMTKImpl", "IllegalArgumentException getSimState wrong ", true);
            return 0;
        } catch (InvocationTargetException e3) {
            e.d("mutiCardMTKImpl", "InvocationTargetException getSimState wrong ", true);
            return 0;
        } catch (RuntimeException e4) {
            e.d("mutiCardMTKImpl", "RuntimeException getSimState wrong ", true);
            return 0;
        } catch (Exception e5) {
            e.d("mutiCardMTKImpl", "Exception getSimState wrong ", true);
            return 0;
        }
    }
}
